﻿<%@ Control Language="C#" AutoEventWireup="true" CodeFile="DialogEmbedJwplayer.ascx.cs"
    Inherits="Ajax_RadEditor_DialogEmbedJwplayer" %>
<%@ Import Namespace="Portal.Core" %>
<link type="text/css" rel="stylesheet" href="<%=CoreContext.absStaticFile%>Themes/JS/jquery.autocomplete-1.1.3/styles.css"
    media="screen" />
<script type='text/javascript' src='<%=CoreContext.absStaticFile%>Themes/JS/jquery-1.7.1.min.js'> </script>
<script type="text/javascript" src="<%=CoreContext.absStaticFile%>Themes/JS/jquery.autocomplete-1.1.3/jquery.autocomplete.js"></script>
<%--http://www.devbridge.com/projects/autocomplete/jquery/--%>
<input type="text" id="title" name="title" value="" size="50" />
<input type="button" onclick="javascript:embedObject();" value="Nhúng vào bài viết" /><br />
Chiều dài player:
<input type="text" id="plWidth" /><br />
Chiều rộng player:
<input type="text" id="plHeight" /><br />
<div id="preview_video">
</div>
<script type="text/javascript">
    String.format = function () {
        var s = arguments[0];
        for (var i = 0; i < arguments.length - 1; i++) {
            var reg = new RegExp("\\{" + i + "\\}", "gm");
            s = s.replace(reg, arguments[i + 1]);
        }
        return s;
    };

    var dataTitle, dataID, data;
    var pathSwf = '<%=CoreContext.absStaticFile%>Themes/JS/jwplayer/player.swf';
    var streamer = "streamer=rtmp://edge01.fms.dutchview.nl/botr";
    var markObject = "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' width='{0}' height='{1}' id='{2}' name='{2}'><param name='movie' value='{3}'><param name='allowfullscreen' value='true'><param name='allowscriptaccess' value='always'><param name='wmode' value='transparent'><param name='flashvars' value='{4}'><embed id='{2}' name='{2}' src='{3}' width='{0}' height='{1}' bgcolor='#000000' allowscriptaccess='always' allowfullscreen='true' flashvars='{4}' /></object>";
    var obj = {};
    jQuery('#title').autocomplete({
        serviceUrl: '<%=CoreContext.basepath%>Ajax.aspx',
        params: {
            p: 'VideoClip'
        },
        minChars: 2,
        delimiter: /(,|;)\s*/, // regex or character
        fnFormatResult: function (value, data, currentValue) {
            return value;
        },
        onSelect: function (value, data, el, index, aData) {
            
            var d = new Date();
            var playerId = 'pl' + d.valueOf();
            var img = aData.imgs[index];
            //            $('#preview_video').html(String.format(markObject, $('#plWidth').val(), $('#plHeight').val(), playerId, pathSwf, data, img));
            $('#preview_video').html(String.format(markObject, $('#plWidth').val(), $('#plHeight').val(), playerId, pathSwf, data));
        }
    });

    if (window.attachEvent) {
        window.attachEvent("onload", initDialog);
    }
    else if (window.addEventListener) {
        window.addEventListener("load", initDialog, false);
    }

    var ePlWidth = document.getElementById("plWidth");
    var ePlHeight = document.getElementById("plHeight");
    var objectArgs = null;

    function getRadWindow() {
        if (window.radWindow) {
            return window.radWindow;
        }
        if (window.frameElement && window.frameElement.radWindow) {
            return window.frameElement.radWindow;
        }
        return null;
    }

    function initDialog() {
        var clientParameters = getRadWindow().ClientParameters; //return the arguments supplied from the parent page
        //jQuery('#title').val(clientParameters.title);
        //jQuery('#preview_video').html(clientParameters.embed);
        ePlWidth.value = clientParameters.plWidth;
        ePlHeight.value = clientParameters.plHeight;
        objectArgs = clientParameters; // gan object lay dc tu parent (clientParameters)
    }

    function embedObject() //fires when the Insert Link button is clicked
    {
        objectArgs.title = jQuery('#title').val();
        objectArgs.embed = jQuery('#preview_video').html();
        objectArgs.plWidth = ePlWidth.value;
        objectArgs.plHeight = ePlHeight.value;
        getRadWindow().close(objectArgs); //use the close function of the getRadWindow to close the dialog and pass the arguments from the dialog to the callback function on the main page.
    }

    //
    

</script>
